package com.ctshk.sapp.scenic.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.scenic.dto.*;
import com.ctshk.rpc.scenic.req.*;
import com.ctshk.rpc.scenic.service.IScenicProductService;
import com.ctshk.rpc.scenic.service.OceanParkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author xuhui
 * @since 2/2/2021
 */

@Api(value="产品中心景点门票", tags="产品中心景点门票")
@RestController
@RequestMapping("/scenic-product")
@Slf4j
public class ScenicProductController extends BaseController {

    @DubboReference
    IScenicProductService scenicProductService;

    @DubboReference
    OceanParkService oceanParkService;

    @ApiOperation(value="查询门票产品列表", notes="查询门票产品列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询门票产品列表", operDesc = "查询门票产品列表")
    @PostMapping("/list")
    public Result<PageResponse<ScenicProductListDTO>>  listScenicProduct(@RequestBody ScenicProductListReq scenicProductListReq){
        log.info("开始查询列表");
        PageResponse<ScenicProductListDTO> pageResponse= scenicProductService.list(scenicProductListReq,getCurrentUser(getRequest()));
        log.info("查询完成，开始返回给前端");
        return Result.success(pageResponse);
    }

    @ApiOperation(value="修改门票推荐状态", notes="是否推荐 0 否 1 是")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改门票推荐状态", operDesc = "是否推荐 0 否 1 是")
    @PostMapping("/modify-recommend-status")
    public Result  modifyRecommendStatus(@RequestBody ScenicProductModifyRecommendStatusReq scenicProductModifyRecommendStatusReq){
         return  scenicProductService.modifyRecommendStatus(scenicProductModifyRecommendStatusReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="门票产品上架", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "门票产品上架", operDesc = "门票产品上架")
    @PostMapping("/putaway")
    public Result  putAway(@RequestBody ScenicProductBatchSaleStrategyReq scenicProductBatchSaleStrategyReq){
         return  scenicProductService.putAway(scenicProductBatchSaleStrategyReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="门票产品库存详情", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "门票产品上架", operDesc = "门票产品上架")
    @PostMapping("/stock-detail")
    public Result<ScenicStockDetailDTO>  stockDetail(@RequestBody ScenicProductStockDetailReq scenicProductBatchSaleStrategyReq){
         return  scenicProductService.stockDetail(scenicProductBatchSaleStrategyReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="景点门票详情", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "景点门票详情", operDesc = "景点门票详情")
    @PostMapping("/scenic-detail")
    public Result<ScenicProductDetailDTO>  scenicDetail(@RequestBody ScenicProductReq scenicProductReq) throws ParseException {
        return  scenicProductService.scenicProductDetai(scenicProductReq);
    }

    @ApiOperation(value="门票产品上架编辑详情", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "门票产品上架", operDesc = "门票产品上架")
    @PostMapping("/scenic-edit-detail")
    public Result<List<ScenicProductSaleStrategyDTO>>  scenicEdit(@RequestBody ScenicProductEditReq scenicProductEditReq){
        return  scenicProductService.scenicProductEditDetai(scenicProductEditReq);
    }

    @ApiOperation(value="景点门票成本价集合", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "景点门票成本价集合", operDesc = "景点门票成本价集合")
    @PostMapping("/price-list")
    public Result<List<ScenicProductPriceListDTO>> scenicProductPriceList(@RequestBody ScenicProductPriceListReq scenicProductPriceListReq){
        return Result.success(scenicProductService.scenicProductPriceList(scenicProductPriceListReq));
    }

    @ApiOperation(value="景点门票成本价详情", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "景点门票成本价详情", operDesc = "景点门票成本价详情")
    @PostMapping("/price-detail")
    public Result<ScenicProductPriceListDTO> scenicProductPriceDetail(@RequestBody ScenicProductPriceDetailReq scenicProductPriceDetailReq){
        return scenicProductService.scenicProductPriceDetail(scenicProductPriceDetailReq , getCurrentUser(getRequest()));
    }

    @ApiOperation(value="拉取产品信息", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "拉取产品信息", operDesc = "拉取产品信息")
    @PostMapping("/save")
    public Result saveScenicProduct(){
        return scenicProductService.saveScenicProduct(getCurrentUser(getRequest()));
    }

    @ApiOperation(value="拉取产品价格日历信息", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "拉取产品价格日历信息", operDesc = "拉取产品价格日历信息")
    @PostMapping("/save-price")
    public Result saveScenicProductPrice(@RequestBody ChimeLongProductPriceAndStockReq req){
        return scenicProductService.saveScenicProductPrice(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value="获取产品库存信息", notes="")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取产品库存信息", operDesc = "获取产品库存信息")
    @PostMapping("/get-stock")
    public Result<StockData> getProductStockChimeLong(@RequestBody ChimeLongProductPriceAndStockReq req){
        return scenicProductService.getProductStockChimeLong(req);
    }

    @ApiOperation(value = "长隆店下单", notes = "长隆店下单")
    @PostMapping(value = "/chimeLong/createOrder")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "新增门票", operDesc = "新增门票")
    public Result createOrder(@RequestBody @Valid ChimeLongCreateOrderPreDTO chimeLongCreateOrderPreDTO) {
        TokenUser user = getCurrentUser(getRequest());
        return scenicProductService.chimeLongOrderCreate(chimeLongCreateOrderPreDTO,user);
    }

    @ApiOperation(value = "长隆酒店取消订单", notes = "长隆酒店取消订单")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "长隆酒店取消订单", operDesc = "长隆酒店取消订单")
    @GetMapping(value = "/chimeLong/cancelOrder")
    public Result cancelOrder(@RequestParam(value = "chimeLongIdOrOtaId", required = true) String chimeLongIdOrOtaId) {
        TokenUser user = getCurrentUser(getRequest());
        return scenicProductService.chimeLongOrderCancel(chimeLongIdOrOtaId,user);
    }

    @ApiOperation(value = "拉取海洋公园产品", notes = "拉取海洋公园产品")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "拉取海洋公园产品", operDesc = "拉取海洋公园产品")
    @GetMapping(value = "/oceanPark/getEvents")
    public Result getEvents() {
        TokenUser user = getCurrentUser(getRequest());
        return oceanParkService.getEvents(user);
    }

    @ApiOperation(value = "拉取海洋公园产品", notes = "拉取海洋公园产品")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "拉取海洋公园产品", operDesc = "拉取海洋公园产品")
    @PostMapping(value = "/oceanPark/getSpecificDates")
    public Result getSpecificDates(@RequestBody @Valid OceanParkReq req) {
        TokenUser user = getCurrentUser(getRequest());
        return oceanParkService.getSpecificDates(user,req);
    }

    @ApiOperation(value = "拉取海洋公园产品票证", notes = "拉取海洋公园产品票证")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "拉取海洋公园产品票证", operDesc = "拉取海洋公园产品票证")
    @PostMapping(value = "/oceanPark/getTickets")
    public Result getSpecificDates(@RequestBody @Valid ScenicProductTicketsReq scenicProductTicketsReq) {
        TokenUser user = getCurrentUser(getRequest());
        return oceanParkService.getTickets(user,scenicProductTicketsReq);
    }

    @ApiOperation(value="根据ids查询门票产品列表", notes="根据ids查询门票产品列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据ids查询门票产品列表", operDesc = "根据ids查询门票产品列表")
    @PostMapping("/getListByIds")
    public Result<List<ScenicProductListDTO>>  getListByIds(@RequestBody ScenicProductListReq scenicProductListReq){
        return scenicProductService.getListByIds(scenicProductListReq);
    }

    @ApiOperation(value="根据产品id查询其代理商列表信息", notes="根据产品id查询其代理商列表信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据产品id查询其代理商列表信息", operDesc = "根据产品id查询其代理商列表信息")
    @GetMapping("/getAgentListByProductId")
    public Result<List<ScenicProductChannelOfflineAgentCustomDTO>> getAgentListByProductId(@RequestParam(value = "productId", required = true) String productId,
                                                                                           @RequestParam(value = "stockId", required = true) String stockId,
                                                                                           @RequestParam(value = "name", required = true) String name
    ){

        return scenicProductService.getAgentListByProductId(Long.parseLong(productId),
                stockId, getCurrentUser(getRequest()),name);
    }
}